<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Login</title>
</head>
<body>
<h1>Spring Security</h1>
<form method="post" action="" onsubmit="return false">
  <div>
    用户名：<input type="text" name="username" id="username">
  </div>
  <div>
    密码：<input type="password" name="password" id="password">
  </div>
  <div>
    驗證碼：<input type="text" name="code" id="code">
  </div>
  <div>
    <!--        <label><input type="checkbox" name="remember-me" id="remember-me"/>自动登录</label>-->
    <button onclick="login()">登陆</button>
  </div>
</form>
</body>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
  function login() {
    var username = document.getElementById("username").value;
    var password = document.getElementById("password").value;
    var code = document.getElementById("code").value;
    // var rememberMe = document.getElementById("remember-me").value;
    $.ajax({
      async: false,
      type: "POST",
      dataType: "json",
      url: '/login',
      contentType: "application/json",
      data: JSON.stringify({
        "username": username,
        "password": password,
        "code":code
        // "remember-me": rememberMe
      }),
      success: function (result) {
        console.log(result)
        if (result.code == 200) {
          alert("登陆成功");
          window.location.href = "../home.html";
        } else {
          alert(result.message)
        }
      }
    });
  }
</script>
</html>
